const express = require("express");
const app = express();
app.get("/", (req, res) => {
  res.send("Hello Express!");
});

var expressWs = require('express-ws')(app);
app.ws('/socketTest', function (ws, req){
  console.log('WebSocket connection established');
  ws.on('message', function (msg) {
    console.log(`receive message ${msg}`)      
  })
  ws.on('close', () => {
    console.log('WebSocket connection closed');
  });
  ws.send('这是服务端的信息')
})

app.get("/test", (req, res) => {
  res.sendFile(__dirname + "/test.html");
});
var module1 = require('./module1');
app.use('/', module1);

app.listen(3000, () => {
  console.log(`Server is running on http://localhost:3000`);
});